package com.yanqu.road.server.gameplayer.module.player;

import com.yanqu.road.connect.ServerLinkControl;
import com.yanqu.road.entity.activity.args.RechargeVipArgs;
import com.yanqu.road.entity.enums.*;
import com.yanqu.road.entity.log.LoginRewardSilverLog;
import com.yanqu.road.entity.player.PlayerState;
import com.yanqu.road.entity.player.UserHistoryAttribute;
import com.yanqu.road.entity.player.UserInfo;
import com.yanqu.road.entity.servercenter.ServerInfo;
import com.yanqu.road.entity.task.args.UnionRiseRankArgs;
import com.yanqu.road.logic.config.GameConfig;
import com.yanqu.road.logic.rank.RankListModel;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.player.PlayerProto;
import com.yanqu.road.server.GameServer;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.ActivityMallModule;
import com.yanqu.road.server.gameplayer.module.activity.ActivityModule;
import com.yanqu.road.server.gameplayer.module.activity.ad.AdActivityModule;
import com.yanqu.road.server.gameplayer.module.activity.advertisement.AdvertisementActivityModule;
import com.yanqu.road.server.gameplayer.module.activity.bulletscreen.BulletScreenModule;
import com.yanqu.road.server.gameplayer.module.activity.coupon.CouponActivityModule;
import com.yanqu.road.server.gameplayer.module.activity.curio.CurioModule;
import com.yanqu.road.server.gameplayer.module.activity.douluodalu.DouLuoDaLuModule;
import com.yanqu.road.server.gameplayer.module.activity.evefeast.EveFeastModule;
import com.yanqu.road.server.gameplayer.module.activity.fanxiuspring.FanXiuSpringModule;
import com.yanqu.road.server.gameplayer.module.activity.flowercard.FlowerCardsModule;
import com.yanqu.road.server.gameplayer.module.activity.flowerstudy.FlowerStudyModule;
import com.yanqu.road.server.gameplayer.module.activity.foxcard.FoxCardModule;
import com.yanqu.road.server.gameplayer.module.activity.game2048.PageantModule;
import com.yanqu.road.server.gameplayer.module.activity.greattrade.GreatTradeModule;
import com.yanqu.road.server.gameplayer.module.activity.iceservergift.IceServerGiftModule;
import com.yanqu.road.server.gameplayer.module.activity.jiuzhou.JiuZhouModule;
import com.yanqu.road.server.gameplayer.module.activity.jumppot.HotpotJumpModule;
import com.yanqu.road.server.gameplayer.module.activity.mammonhall.MammonHallModule;
import com.yanqu.road.server.gameplayer.module.activity.pasture.PastureModule;
import com.yanqu.road.server.gameplayer.module.activity.ppl.PplModule;
import com.yanqu.road.server.gameplayer.module.activity.qixi.QixiModule;
import com.yanqu.road.server.gameplayer.module.activity.recallplayer.RecallPlayerModule;
import com.yanqu.road.server.gameplayer.module.activity.share.ShareModule;
import com.yanqu.road.server.gameplayer.module.activity.shuihuyezicard.ShuiHuYeZiCardModule;
import com.yanqu.road.server.gameplayer.module.activity.signindraw.SignInDrawModule;
import com.yanqu.road.server.gameplayer.module.activity.springdinner.SpringDinnerModule;
import com.yanqu.road.server.gameplayer.module.activity.springunionbanquet.SpringUnionBanquetModule;
import com.yanqu.road.server.gameplayer.module.activity.starlight.StarLightModule;
import com.yanqu.road.server.gameplayer.module.activity.tongbing.TongBingModule;
import com.yanqu.road.server.gameplayer.module.activity.unionchest.UnionChestModule;
import com.yanqu.road.server.gameplayer.module.activity.yuanbaolottery.YuanBaoLotteryModule;
import com.yanqu.road.server.gameplayer.module.base.GeneralModule;
import com.yanqu.road.server.gameplayer.module.beautyescort.BeautyEscortModule;
import com.yanqu.road.server.gameplayer.module.charitable.CharitableModule;
import com.yanqu.road.server.gameplayer.module.creditpoints.CreditPointsModule;
import com.yanqu.road.server.gameplayer.module.cricket.CricketModule;
import com.yanqu.road.server.gameplayer.module.hunt.HuntModule;
import com.yanqu.road.server.gameplayer.module.kowloon.KowloonModule;
import com.yanqu.road.server.gameplayer.module.kuang.KuangModule;
import com.yanqu.road.server.gameplayer.module.mall.MallModule;
import com.yanqu.road.server.gameplayer.module.manor.ManorModule;
import com.yanqu.road.server.gameplayer.module.match.MatchModule;
import com.yanqu.road.server.gameplayer.module.mogulbirthday.MogulBirthdayModule;
import com.yanqu.road.server.gameplayer.module.musicroom.MusicRoomModule;
import com.yanqu.road.server.gameplayer.module.relatives.RelativesModule;
import com.yanqu.road.server.gameplayer.module.retrieveReward.RecoveryRewardModule;
import com.yanqu.road.server.gameplayer.module.sacrifice.SacrificeModule;
import com.yanqu.road.server.gameplayer.module.sign.SignModule;
import com.yanqu.road.server.gameplayer.module.specialcookboy.SpecialCookBoyModule;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.gameplayer.module.travel.TravelModule;
import com.yanqu.road.server.gameplayer.module.union.cross.CrossUnionModule;
import com.yanqu.road.server.gameplayer.module.union.cross.CrossUnionTradeModule;
import com.yanqu.road.server.gameplayer.module.union.cross.UnionHuaBenModule;
import com.yanqu.road.server.gameplayer.module.unioncampwar.UnionCampWarModule;
import com.yanqu.road.server.gameplayer.module.vehicle.VehicleModule;
import com.yanqu.road.server.gameplayer.module.verification.VerificationModule;
import com.yanqu.road.server.gameplayer.module.wingroom.WingRoomChakraModule;
import com.yanqu.road.server.gameplayer.module.wingroom.WingRoomMessageModule;
import com.yanqu.road.server.gameplayer.module.wingroom.WingRoomModule;
import com.yanqu.road.server.gameplayer.module.workshop.WorkShopModule;
import com.yanqu.road.server.gameplayer.module.xiaomian.XiaoMianModule;
import com.yanqu.road.server.gameplayer.module.zhaoshang.ZsModule;
import com.yanqu.road.server.manger.DataAnalyticsMgr;
import com.yanqu.road.server.manger.ForbiddenIpMgr;
import com.yanqu.road.server.manger.ServerListMgr;
import com.yanqu.road.server.manger.activity.dafuweng.DaFuWengMgr;
import com.yanqu.road.server.manger.log.AutoLogMgr;
import com.yanqu.road.server.manger.config.SystemOpenMgr;
import com.yanqu.road.server.manger.log.LogMgr;
import com.yanqu.road.server.manger.maidian.UserBagGoodsChangeMgr;
import com.yanqu.road.server.manger.messagesubscribe.MessageSubscribeMgr;
import com.yanqu.road.server.manger.player.UserMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.manger.rank.RankMgr;
import com.yanqu.road.server.manger.sacrifice.SacrificeMgr;
import com.yanqu.road.server.manger.union.CrossUnionMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.LocalDateTimeHelper;
import com.yanqu.road.utils.date.DateHelper;
import com.yanqu.road.utils.property.Property;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Objects;

/**
 * 赚钱速度模块
 */
public class EarnSpeedModule extends GeneralModule {
    /**
     * 玩家赚速
     */
    private BigInteger earnSpeed = BigInteger.ZERO;

    private final Object lockObj = new Object();

    private boolean scheduling = false;

    private long lastResetTime;

    private BigInteger buildingEarnSpeed = BigInteger.ZERO;      //店铺赚速

    public EarnSpeedModule(GamePlayer player) {
        super(player);
    }

    @Override
    public boolean loadData() {
        return true;
    }

    @Override
    public boolean afterLoadData() {
        scheduleAddSilver();
        return false;
    }

    @Override
    public boolean saveData() {
        return true;
    }

    @Override
    public void loginSendMsg() {
        player.getModule(AttributeModule.class).syncAllAttribute();
    }

    public BigInteger getEarnSpeed() {
        return earnSpeed;
    }

    public void loginAddSilver() {
        synchronized (lockObj) {
            long lastAutoAddSilverTime = player.getModule(AttributeModule.class).getAttribute(ePlayerAttrType.LastAutoAddSilverTime);
            if (lastAutoAddSilverTime != 0) {
                long nowTime = System.currentTimeMillis() / 1000;
                long subValue = nowTime - lastAutoAddSilverTime;
                //离线最多的收益
                if (subValue > GameConfig.OFFLINE_REVENUE_MAX_TIME) {
                    subValue = GameConfig.OFFLINE_REVENUE_MAX_TIME;
                }
                //计算金币速度
                calEarnSpeed();
                player.getModule(PlayerModule.class).checkSystemOpen();
                BigInteger oldSilver = player.getUserInfo().getSilver();
                BigInteger addSilver = addSilver(subValue);
                BigInteger curSilver = player.getUserInfo().getSilver();
                // 下发离线收益
                if (addSilver.compareTo(BigInteger.ZERO) > 0) {
                    PlayerProto.OfflineRevenueMsg.Builder offlineMsg = PlayerProto.OfflineRevenueMsg.newBuilder();
                    offlineMsg.setOfflineTime((int) (nowTime - lastAutoAddSilverTime));
                    offlineMsg.setSilver(addSilver.toString());
                    player.sendPacket(Protocol.U_OFFLINE_REVENUE, offlineMsg);
                    DataAnalyticsMgr.trackOffline(player, offlineMsg.getOfflineTime(), offlineMsg.getSilver());
                }
                player.getModule(AttributeModule.class).setAttribute(ePlayerAttrType.LastAutoAddSilverTime, nowTime);
//                addLoginAddSilverLog(player.getUserId(), lastAutoAddSilverTime * 1000, player.getUserInfo().getSilver(), System.currentTimeMillis(), curSilver, addSilver);
                AutoLogMgr.add(new LoginRewardSilverLog(getUserId(), lastAutoAddSilverTime * 1000, player.getUserInfo().getSilver(), System.currentTimeMillis(), curSilver, addSilver));

            }
        }
    }


    /**
     * 重新计算玩家赚钱速度
     */
    private void calEarnSpeed() {
        long nowTime = System.currentTimeMillis() / 1000;
        //自动恢复祝福值
        UserMgr.autoRecoverHeart(player.getUserInfo());
        //历史最高变化
        UserHistoryAttribute userHistoryAttribute = player.getModule(PlayerModule.class).getUserHistoryAttribute();
        //店铺赚速
        BigDecimal buildEarnSpeed = new BigDecimal(player.getModule(BuildingModule.class).calEarnSpeed());
        BigInteger curBuildingEarnSpeed = buildEarnSpeed.toBigInteger();
        if(!Objects.equals(curBuildingEarnSpeed, buildingEarnSpeed)){
            buildingEarnSpeed = curBuildingEarnSpeed;
        }
        if (curBuildingEarnSpeed.compareTo(userHistoryAttribute.getTopBuildingEarnSpeed()) > 0) {//店铺历史赚速变更
            userHistoryAttribute.setTopBuildingEarnSpeed(curBuildingEarnSpeed);
        }
        //子嗣赚速
        BigDecimal childEarnSpeed = new BigDecimal(player.getUserInfo().getChildEarnSpeed());

        BigDecimal baseEarnSpeed = buildEarnSpeed.add(childEarnSpeed);
        BigInteger tempBaseEarnSpeed = baseEarnSpeed.toBigInteger();
        if (tempBaseEarnSpeed.compareTo(player.getUserInfo().getBaseEarnSpeed()) != 0) {//基础赚速变化
            player.getUserInfo().setBaseEarnSpeed(tempBaseEarnSpeed);
        }
        //加成
        BigDecimal addition = BigDecimal.ONE;
        //特权卡加成，赚速冲榜需要算进去
        addition = addition.add(BigDecimal.valueOf(player.getModule(CardModule.class).getEarnSpeedAddition()).divide(BigDecimal.valueOf(1000), 4, BigDecimal.ROUND_UP));
        //活动赚速
        BigInteger abilityEarnSpeed = baseEarnSpeed.multiply(addition).setScale(0, BigDecimal.ROUND_UP).toBigInteger(); //去除拜访加成的赚速

        //历史最高赚速,用历史最高店铺赚速、子嗣赚速，去除拜访加成的赚速
        BigDecimal calValue = new BigDecimal(userHistoryAttribute.getTopBuildingEarnSpeed());
        calValue = calValue.add(childEarnSpeed);
        BigInteger topEarnSpeed = calValue.multiply(addition).setScale(0, BigDecimal.ROUND_UP).toBigInteger();

        //点赞、蛊惑加成，赚速冲榜不算进去
        addition = addition.add(BigDecimal.valueOf(player.getModule(PlayerModule.class).getHeartAddition()).divide(BigDecimal.valueOf(1000), 4, BigDecimal.ROUND_UP));
        //看广告赚速加成
        addition = addition.add(BigDecimal.valueOf(player.getModule(AdvertisementActivityModule.class).getEarnSpeedAddition()).divide(BigDecimal.valueOf(1000), 4, BigDecimal.ROUND_UP));

        BigInteger newEarnSpeed = baseEarnSpeed.multiply(addition).setScale(0, BigDecimal.ROUND_UP).toBigInteger();
        if (!newEarnSpeed.equals(earnSpeed)) {//赚速变化
            earnSpeed = newEarnSpeed;
            player.getModule(TradeWarBuildingModule.class).calcBuildingReward(eTradeWarBuildingType.TaxOffice.getValue(), nowTime);
            player.notifyListener(eGamePlayerEventType.EarnSpeed.getValue(), earnSpeed);
            player.notifyListener(eGamePlayerEventType.EarnSpeedFund.getValue(), earnSpeed);
            //赚速榜
            RankMgr.changeUserRank(eBigRankType.Normal.getValue(), player.getUserId(), earnSpeed, eRankType.EarnSpeed.getValue(), "");
            //家族赚速变化
            CrossUnionMgr.updateMemberEarnSpeed(player);
        }

        if (topEarnSpeed.compareTo(userHistoryAttribute.getEarnSpeed()) > 0) {

            boolean afterInitPreValue = GamePlayerMgr.getPlayerMap().containsKey(getUserId()); // 玩家进map后，才能保证赚速榜preValue设置完毕
            if (afterInitPreValue) {
                userHistoryAttribute.setEarnSpeed(topEarnSpeed);
                player.getModule(PlayerModule.class).syncUserHistoryAttribute();
            }

            // 历史最高赚速变化更新寒冬建筑任务(只有寒冬特色服或者系统解锁了需要变更)
            ServerInfo serverInfo = ServerListMgr.getServerInfo(GameServer.getInstance().getServerId());
            if (serverInfo.getSpecialServer() == eSpecialServerType.IceServer.getValue() || SystemOpenMgr.systemOpen(player, eSystemId.IceServer.getValue())) {
                player.notifyListener(eGamePlayerEventType.IceServerUpgradeBuilding.getValue());
            }
        }
        //赚速提升冲榜
        player.notifyListener(eGamePlayerEventType.EarnSpeedRiseRank.getValue(), abilityEarnSpeed);   //用去除拜访加成的赚速
        player.notifyListener(eGamePlayerEventType.UnionEarnSpeedRiseRank.getValue(), new UnionRiseRankArgs(UnionRiseRankArgs.NOTIFY_TYPE_NORMAL,
                abilityEarnSpeed, player.getUserInfo().getUnionUid()));      //用去除拜访加成的赚速

        player.getModule(PlayerModule.class).getUserInfo().setEarnSpeed(earnSpeed);
        player.setLastCalEarnSpeedTime(nowTime);
        player.getModule(RecallPlayerModule.class).updateTaskFromSystem(eRecallPlayerConditionTypeEnum.totalEarnRise,earnSpeed);
    }

    private BigInteger addSilver(long time) {
        BigInteger addValue = BigInteger.valueOf(time).multiply(earnSpeed);
        // 如果有统兵活动会在被任命后减少银两收成
        int reduce = player.getModule(TongBingModule.class).getPositionReduce();
        addValue = addValue.multiply(BigInteger.valueOf(1000).add(BigInteger.valueOf(reduce))).divide(BigInteger.valueOf(1000));
        if (addValue.compareTo(BigInteger.ZERO) > 0) {
            player.getModule(CurrencyModule.class).addCurrency(new Property(GameConfig.GAME_MONEY_SILVER, addValue),
                    eLogMoneyType.System, eLogMoneyType.AutoAddSilver);
        }
        return addValue;
    }

    public void scheduleAddSilver() {
        scheduleAddSilver(false);
    }

    /**
     * 定时计算玩家目前金钱数
     */
    public void scheduleAddSilver(boolean checkTime) {
        if (scheduling) {
            return;
        }
        synchronized (lockObj) {
            scheduling = true;
            try {
                if (checkTime) {
                    if ((System.currentTimeMillis() / 1000 - player.getLastCalEarnSpeedTime()) > 20) {
                        calEarnSpeed();
                    }
                } else {
                    calEarnSpeed();
                }

                player.getModule(PlayerModule.class).checkSystemOpen();
                player.getModule(PlayerModule.class).notifyCouponEvent();

                if (player.getState() == PlayerState.ONLINE) {
                    long lastCalTime = player.getModule(AttributeModule.class).getAttribute(ePlayerAttrType.LastAutoAddSilverTime);
                    long currentTime = System.currentTimeMillis() / 1000;
                    int addTime = (int) (currentTime - lastCalTime);
                    if (addTime > 0) {
                        addSilver(addTime);
                        //钱庄自动产金
                        player.getModule(HouseModule.class).autoClickHouse(addTime);
                        //设置玩家收益时间
                        player.getModule(AttributeModule.class).setAttribute(ePlayerAttrType.LastAutoAddSilverTime, currentTime);
                        MessageSubscribeMgr.setOffLineTime(player.getUserId(),currentTime);
                        syncEarnSpeed();
                    }
                }
            } catch (Exception e) {
                log.error("scheduleAddSilver error.",e);
            }
            scheduling = false;

            // 如果是被封禁的IP 则踢下线
            if (ForbiddenIpMgr.isForbiddenIp(player.getWebSocketIp())) {
                YanQuMessage castleReq = new YanQuMessage(Protocol.A_KICK_OUT_PLAYER);
                castleReq.setPlayerId(player.getUserId());
                ServerLinkControl.send(player.getUserId(), castleReq);
            }
        }
    }

    private void syncEarnSpeed() {
        PlayerProto.EarnSpeedTempMsg.Builder msg = PlayerProto.EarnSpeedTempMsg.newBuilder();
        UserInfo userInfo = player.getUserInfo();
        msg.setTotalSilver(userInfo.getSilver().toString());
        msg.setEarnSpeed(earnSpeed.toString());
        msg.setChildEarnSpeed(userInfo.getChildEarnSpeed().toString());
        int rank = -1;
        RankListModel rankListModel = RankMgr.getRankListModelByType(eBigRankType.Normal.getValue(), eRankType.EarnSpeed.getValue());
        if (null != rankListModel) {
            rank = rankListModel.unlockGetMyRank(player.getUserId());
        }
        msg.setEarnSpeedRank(rank);
        msg.setBuildingEarnSpeed(buildingEarnSpeed.toString());
        msg.setTopBuildingEarnSpeed(player.getModule(PlayerModule.class).getUserHistoryAttribute().getTopBuildingEarnSpeed().toString());
        player.sendPacket(ClientProtocol.U_EARN_SPEED_SYNC, msg);
    }

    // 每日重置玩家数据
    public void resetDay() {
        synchronized (lockObj) {
            ActivityModule activityModule = player.getModule(ActivityModule.class);
            activityModule.startChanges();
            long zeroTime = LocalDateTimeHelper.getZeroTimeTimeStamp() / 1000;
            if (lastResetTime < zeroTime) {
                AttributeModule attributeModule = player.getModule(AttributeModule.class);
                long resetAttrTime = attributeModule.getAttribute(ePlayerAttrType.ResetAttrTime);

                //重置日常任务
                player.getModule(TaskModule.class).resetOneDay();
                //重置密卷七日轮回
                player.getModule(SecretVolumeModule.class).resetSecretVolume();
                //七日活动到期移除监听
                player.getModule(TaskModule.class).checkSevenDayTask();
                //重置商城
                player.getModule(MallModule.class).resetOneDay();
                //重置座骑
                player.getModule(VehicleModule.class).resetOneDay();
                //重置商战
                player.getModule(TradeWarModule.class).resetOneDay();
                //重置出游
                player.getModule(TravelModule.class).resetOneDay();
                //重置联姻刷新次数
                player.getModule(MarriageModule.class).resetOneDay();
                //重置乔迁风云膜拜
                player.getModule(EstateWarModule.class).resetOneDay();
                //重置寻宝
                player.getModule(MineWarModule.class).resetOneDay();
                //活动盐场
                player.getModule(OreWarModule.class).resetOneDay();
                //重置点赞、蛊惑
                player.getModule(InteractiveModule.class).resetOneDay();
                //重置商会
                player.getModule(CrossUnionModule.class).resetOneDay();
                //重置狩猎
                player.getModule(HuntModule.class).resetOneDay();
                //重置祭天
                player.getModule(SacrificeModule.class).resetOneDay();
                //重置财神神迹
                player.getModule(MammonModule.class).resetOneDay();
                //玩家每日数据
                player.getModule(DailyDataModule.class).resetOneDay();
                //重置通用活动
                player.getModule(ActivityMallModule.class).resetOneDay();
                //重置活动信息
                player.getModule(ActivityModule.class).resetOneDay();
                //重置亲家信息
                player.getModule(RelativesModule.class).resetOneDay();
                //祭天记录数据
                SacrificeMgr.taskRecordPlayerInfo(player);
                //行善重置
                player.getModule(CharitableModule.class).resetOneDay();
                //选美大会重置
                player.getModule(PageantModule.class).resetOneDay();
                //泡泡龙重置（在activityScore重置前先重置，否则积分会算2天的）
                player.getModule(PplModule.class).dailyReset();
                //商贸派遣重置
                player.getModule(CrossUnionTradeModule.class).resetOneDay();
                //招商重置
                player.getModule(ZsModule.class).resetOneDay();
                //弹幕重置
                player.getModule(BulletScreenModule.class).resetOneDay();
                //杂艺每周刷新门客出战次数
                player.getModule(MatchModule.class).syncVarietyPatrons();
                //活动积分每日重置
                player.getModule(ActivityMallModule.class).activityScoreResetOneDay();
                //走镖
                player.getModule(BeautyEscortModule.class).resetOneDay();
                //财神殿
                player.getModule(MammonHallModule.class).resetOneDay();
                //小面任务
                player.getModule(XiaoMianModule.class).resetOneDay();
                //鱼塘鱼类重置
                player.getModule(ManorModule.class).resetOneDay();
                //斗罗大陆-魂斗
                player.getModule(DouLuoDaLuModule.class).resetOneDay();
                //水浒叶子牌每日次数重置
                player.getModule(ShuiHuYeZiCardModule.class).resetOneDay();
                player.getModule(UnionHuaBenModule.class).resetOneDay();
                //厢房领取呼朋唤友事件奖励每日重置
                player.getModule(WingRoomModule.class).resetOneDay();
                player.getModule(WorkShopModule.class).resetOneDay();
                player.getModule(WingRoomMessageModule.class).resetOneDay();
                // 不良积分每日重置
                player.getModule(CreditPointsModule.class).resetOneDay();
                // 牧场点兵次数每日重置
                player.getModule(PastureModule.class).resetOneDay();
                // 蛐蛐每日执行
                player.getModule(CricketModule.class).resetOneDay();
                //记录玩家在线时长
                player.logOnlineTime();
                //新服福利活动立即刷新用户当天在线时间
                // 大商途
                player.getModule(GreatTradeModule.class).resetOneDay();
                player.getModule(FlowerCardsModule.class).resetOneDay();
                player.getModule(FanXiuSpringModule.class).resetOneDay();
                player.getModule(AdActivityModule.class).dailyReset();
                player.getModule(AdvertisementActivityModule.class).checkAll();
                player.getModule(CouponActivityModule.class).dailyReset();
                player.getModule(VerificationModule.class).resetOneDay();
                player.getModule(RecoveryRewardModule.class).resetOneDay();
                player.getModule(UnionChestModule.class).syncUserData();
                player.getModule(MogulBirthdayModule.class).dayReset();
                player.getModule(SignInDrawModule.class).resetOneDay();
                // 九龙城寨每日重置
                player.getModule(KowloonModule.class).resetOneDay();
                player.getModule(KuangModule.class).resetOneDay();
                player.getModule(UnionCampWarModule.class).resetOneDay();
                //小当家特色服
                player.getModule(SpecialCookBoyModule.class).checkShareCodeUseCountReset();
                //花城书房
                player.getModule(FlowerStudyModule.class).checkPoemRefresh();
                player.getModule(FlowerStudyModule.class).checkVisitRefresh();
                player.getModule(QixiModule.class).resetOneDay(false);
                player.getModule(EveFeastModule.class).resetOneDay(false);
                //厢房命盘
                player.getModule(WingRoomChakraModule.class).resetOneDay();
                //妙音坊
//                player.getModule(MusicRoomModule.class).resetOneDayByHour();
                //屠苏
                player.getModule(SpringUnionBanquetModule.class).resetOneDay();

                //九州
                player.getModule(JiuZhouModule.class).resetOneDay();

                player.getModule(YuanBaoLotteryModule.class).resetOneDay();

                // 美团年夜饭
                player.getModule(SpringDinnerModule.class).resetOneDay();
                player.getModule(FoxCardModule.class).resetOneDay(false);

                player.getModule(HotpotJumpModule.class).resetOneDay(false);

                player.getModule(StarLightModule.class).dailyReset(); // 星星点灯每日补发
                player.getModule(IceServerGiftModule.class).dailyReset(); // 寒冬馈赠每日补发
                player.getModule(WealthScrollModule.class).init();

                if (resetAttrTime < zeroTime) {
                    attributeModule.setAttribute(ePlayerAttrType.ResetAttrTime, System.currentTimeMillis() / 1000);
                    //同步签到信息
                    player.getModule(SignModule.class).syncUserSign();
                    // 重置膜拜次数
                    attributeModule.setAttribute(ePlayerAttrType.RankWorship, 0);
                    //重置每天充值金额
                    attributeModule.setAttribute(ePlayerAttrType.DayTotalRecharge, 0);
                    //累加登录天数
                    attributeModule.addAttribute(ePlayerAttrType.LoginTotalDays, 1);
                    //更新连续登录天数记录
                    if (DateHelper.isNextDay(attributeModule.getAttribute(ePlayerAttrType.LastContinuousLoginTime), zeroTime)) {
                        attributeModule.addAttribute(ePlayerAttrType.ContinuousLoginDays, 1);
                    } else {
                        attributeModule.setAttribute(ePlayerAttrType.ContinuousLoginDays, 1);
                    }
                    attributeModule.setAttribute(ePlayerAttrType.LastContinuousLoginTime, System.currentTimeMillis() / 1000);
                    if (attributeModule.getAttribute(ePlayerAttrType.ContinuousLoginDays) > attributeModule.getAttribute(ePlayerAttrType.LoginMaxDays)) {
                        attributeModule.setAttribute(ePlayerAttrType.LoginMaxDays, attributeModule.getAttribute(ePlayerAttrType.ContinuousLoginDays));
                        player.notifyListener(eGamePlayerEventType.LoginMaxDays.getValue(), attributeModule.getAttribute(ePlayerAttrType.LoginMaxDays));
                    }
                    player.notifyListener(eGamePlayerEventType.LoginDays.getValue(), 1);
                    player.notifyListener(eGamePlayerEventType.HistoryRechargeVipExpDay.getValue(), null);
                    player.notifyListener(eGamePlayerEventType.FirstRechargeVipExpDay.getValue(), null);
                    player.notifyListener(eGamePlayerEventType.RechargeVipExpDay.getValue(), new RechargeVipArgs(0, 1));
                    player.notifyListener(eGamePlayerEventType.LoginTotalDays.getValue(), attributeModule.getAttribute(ePlayerAttrType.LoginTotalDays));
                    player.notifyListener(eGamePlayerEventType.WealthGodGifts.getValue(), 0);
                    player.notifyListener(eGamePlayerEventType.PaintedEggsEvent.getValue());
                    //重置每天送财次数
                    attributeModule.setAttribute(ePlayerAttrType.DisperseGold, 0);
                    //同步活动数据
                    player.getModule(ActivityModule.class).syncActivity();
                    player.getModule(ActivityModule.class).syncSpecialActivityData();
                    //同步dfw玩家数据 刷新商会返利状态
                    DaFuWengMgr.syncDFWUserData(player);
                    player.getModule(CurioModule.class).checkPrivilegeExpire();
                    UserBagGoodsChangeMgr.addUserLoginTime(player.getUserId());
                    if(player.getState() == PlayerState.ONLINE) {//玩家在线才执行
                        long lastLoginTime = player.getUserInfo().getLastLoginTime();
                        if ((System.currentTimeMillis() / 1000 - lastLoginTime) > 24 * 3600 && lastLoginTime > 0) {
                            player.getUserInfo().setLastLoginTime(zeroTime - 3600);
                        }
                    }
                    player.getModule(ShareModule.class).dailyReset();
                }
                lastResetTime = zeroTime;
            }
            activityModule.finishChanges();
        }
    }
}
